//
//  WTFRect.m
//  Courses
//
//  Created by xxx on 15/1/3.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "WTFRect.h"

float ratio()
{
    return [UIScreen mainScreen].bounds.size.width / DEFAULT_WIDTH;
}

CGFloat AutoFloat(CGFloat len)
{
    return len * ratio();
}

CGFloat RevFloat(CGFloat len)
{
    return len / ratio();
}

CGSize AutoSizeMake(CGFloat width, CGFloat height)
{
    CGSize size;
    size.width = width * ratio();
    size.height = height * ratio();
    return size;
}

CGPoint AutoPointMake(CGFloat x, CGFloat y)
{
    return CGPointMake(x * ratio(), y * ratio());
}

CGRect AutoRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height, WTFAutoLayoutType layoutType)
{
    CGRect rect;
    CGFloat xRatio = [UIScreen mainScreen].bounds.size.width / DEFAULT_WIDTH;
    CGFloat yRatio = [UIScreen mainScreen].bounds.size.height / DEFAULT_HEIGHT;
    
    switch(layoutType)
    {
        case WTFAutoLayoutTypeBar:
        {
            rect.origin.x = x * xRatio;
            rect.origin.y = y;
            rect.size.width = width * xRatio;
            rect.size.height = height;
        }
            break;
        case WTFAutoLayoutTypeText:
        case WTFAutoLayoutTypeRaw:
        {
            rect.origin.x = x;
            rect.origin.y = y;
            rect.size.width = width;
            rect.size.height = height;
        }
            break;
        case WTFAutoLayoutTypePic:
        {
            rect.origin.x = x * xRatio;
            rect.origin.y = y * yRatio;
            rect.size.width = width * xRatio;
            rect.size.height = height * yRatio;
        }
            break;
        default:
            break;
    }
    return rect;
}

@implementation WTFRect

@end
